package cn.wokoba.dao.mapper;

import cn.wokoba.dao.pojo.UserRaffleOrder;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

//用户抽奖订单
@Mapper
public interface UserRaffleOrderMapper extends BaseMapper<UserRaffleOrder> {

   // void insert(UserRaffleOrder userRaffleOrder);


    @Select("""
            select user_id, activity_id, activity_name, strategy_id, order_id, order_time, order_state
                    from user_raffle_order
                    where user_id = #{userId} and activity_id = #{activityId} and order_state = 'create'""")
    UserRaffleOrder queryNoUsedRaffleOrder(UserRaffleOrder userRaffleOrderReq);

    @Update("""
             update user_raffle_order
                    set order_state = 'used', update_time = now()
                    where user_id = #{userId} and order_id = #{orderId} and order_state = 'create'\
            """)
    int updateUserRaffleOrderStateUsed(UserRaffleOrder userRaffleOrderReq);

}
